package com.htht.smartschool.action.department;

import java.util.List;
import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.department.TDepartment;
import com.htht.smartschool.service.department.DepartmentService;
import com.htht.smartschool.util.system.GsonUtils;

public class DepartmentAction extends BaseAction{

	public boolean processData(DataContainer obj,ParamData pd) {
		DepartmentService departmentService = new DepartmentService();
		boolean flag = false;
		TDepartment tdepartment = (TDepartment) GsonUtils.getInstance().fromJson(pd.getData(), TDepartment.class);
		if(pd.getCmd().equalsIgnoreCase("addDepartment")){
			flag = departmentService.addDepartment(tdepartment);
			if(flag){
				obj.setData("添加部门成功");
			}else{
				obj.setData("添加部门失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getDepartmentByPage")){
			List<TDepartment> list = departmentService.getDepartmentByPage(tdepartment);
			if(list != null){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateDepartment")){
			flag = departmentService.updateDepartment(tdepartment);
			if(flag){
				obj.setData("修改成功");
			}else{
				obj.setData("修改失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteDepartment")){
			@SuppressWarnings("rawtypes")
			Map map = departmentService.deleteDepartment(tdepartment);
			if(map != null){
				obj.setData(map);
			}else{
				obj.setData("删除失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getAllDepartments")){
			List<TDepartment> result = departmentService.getAllDepartments(tdepartment);
			if(result.size()>0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败！");
			}
		}
		return flag;
	}

}
